/**
 * creater:han.wen@dhc.com.cn
 * create time:2016-06-01 16:06:43
 * describe:轮播图
 */
APP.controller('SlideBoxController', ['$scope', 'SlideBoxService', '$ionicSlideBoxDelegate',
  function ($scope, SlideBoxService, $ionicSlideBoxDelegate) {

    /***变量声明***/
    $scope.imageUrl = undefined;
    $scope.addUrl = undefined;
    $scope.isAdd = undefined;

    /**
     * 初始化函数
     */
    $scope.init = function () {
      $scope.imageUrl = [{
        src: './img/app_zcp.png'
      }, {
        src: './img/app_xf.png'
      }, {
        src: './img/app_gs.png'
      }];
      $scope.addUrl = './img/app_wh.png';
      $scope.isAdd = false;
    };

    /**
     * 添加图片
     */
    $scope.addPic = function () {
      if (!$scope.isAdd) {
        $scope.isAdd = true;
        $scope.imageUrl.push({src: $scope.addUrl});
        $scope.updatePic();
      }
    };

    /**
     * 隐藏图片
     */
    $scope.removePic = function () {
      if ($scope.isAdd) {
        $scope.isAdd = false;
        $scope.imageUrl.pop();
        $scope.updatePic();
      }
    };

    /**
     * 更新轮播图
     */
    $scope.updatePic = function () {
      $ionicSlideBoxDelegate.$getByHandle('noticeHandle').update();
    };

    /**
     * 登录方法
     */
    $scope.login = function () {
      SlideBoxService.doLogin($scope.username, $scope.password)
        .success(function (response, status, headers, config) {

        })
        .error(function (response, status, headers, config) {

        })
    };


    /*
     $scope.init();//如果页面缓存则用此方法初始化
     */
    $scope.$on('$ionicView.beforeEnter', function () {
      $scope.init();
    });
  }
]);

/**
 * creater:han.wen@dhc.com.cn
 * create time:2016-06-01 16:06:43
 * describe:轮播图
 */
APP.service('SlideBoxService', ['$http', 'UrlService', function ($http, UrlService) {
  /**
   * 登录方法
   * @param username  登录用户名
   * @param password  登录密码
   */
  this.doLogin = function (username, password) {
    var param = {
      username: username,
      password: password
    };
    $http.post(UrlService.get('LOGIN'), param);
  }

}]);
